package tmall.framework.service.impl;

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.util.Assert;
import tmall.framework.service.IdService;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public final class AutowiredIdConfigurerIgnoreParents {
    private final ConfigurableListableBeanFactory beanFactory;

    public AutowiredIdConfigurerIgnoreParents(
            ConfigurableListableBeanFactory beanFactory) {
        Assert.notNull(beanFactory, "beanFactory cannot be null");
        this.beanFactory = beanFactory;
    }

    public List<IdService> getIdService(){
        List<IdService> idServiceList = new ArrayList<>();
        Map<String, IdService> idServiceMap = beanFactory.getBeansOfType(IdService.class);
        for(Map.Entry<String,IdService> entry: idServiceMap.entrySet()){
            idServiceList.add(entry.getValue());
        }
        return idServiceList;
    }
}
